﻿using Microsoft.AspNet.Identity;
using System.Threading.Tasks;

namespace Sidvall.IdentityManager.Security.Entities
{
	public partial class AspNetUsers : Microsoft.AspNet.Identity.IUser<string>
	{
		#region AddUserClaim

		public void AddUserClaim(string claimType, string claimValue)
		{
			AddUserClaim(claimType, claimValue, Sidvall.Data.DataRowState.Added);
		}
		public void AddUserClaim(string claimType, string claimValue, Sidvall.Data.DataRowState dataRowState)
		{
			if (this.AspNetUserClaims == null)
				this.AspNetUserClaims = new AspNetUserClaimsCollectionItem();
			this.AspNetUserClaims.Add(this.Id, claimType, claimValue, dataRowState);
		}

		#endregion
		#region AddUserLogin

		public void AddUserLogin(string loginProvider, string providerKey)
		{
			AddUserLogin(loginProvider, providerKey, Sidvall.Data.DataRowState.Added);
		}
		public void AddUserLogin(string loginProvider, string providerKey, Sidvall.Data.DataRowState dataRowState)
		{
			if (this.AspNetUserLogins == null)
				this.AspNetUserLogins = new AspNetUserLoginsCollectionItem();
			this.AspNetUserLogins.Add(this.Id, loginProvider, providerKey, dataRowState);
		}

		#endregion
		#region GenerateUserIdentityAsync

		public async Task<System.Security.Claims.ClaimsIdentity> GenerateUserIdentityAsync(UserManager<AspNetUsers> manager)
		{
			// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
			var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

			return userIdentity;
		}

		#endregion
	}
}